from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-01-17 14:26:11.169374
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 17, Jan, 2021
Time: 14:26:15
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -45.2407
Nobs: 174.000 HQIC: -46.2118
Log likelihood: 1946.04 FPE: 4.39624e-21
AIC: -46.8747 Det(Omega_mle): 2.65867e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.453208 0.147540 3.072 0.002
L1.Burgenland 0.134741 0.076718 1.756 0.079
L1.Kärnten -0.235371 0.062334 -3.776 0.000
L1.Niederösterreich 0.138363 0.177651 0.779 0.436
L1.Oberösterreich 0.229250 0.152056 1.508 0.132
L1.Salzburg 0.178561 0.080686 2.213 0.027
L1.Steiermark 0.080480 0.110215 0.730 0.465
L1.Tirol 0.157659 0.073108 2.157 0.031
L1.Vorarlberg 0.015887 0.069729 0.228 0.820
L1.Wien -0.137804 0.148216 -0.930 0.353
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.521590 0.188421 2.768 0.006
L1.Burgenland 0.014179 0.097975 0.145 0.885
L1.Kärnten 0.372234 0.079606 4.676 0.000
L1.Niederösterreich 0.131373 0.226875 0.579 0.563
L1.Oberösterreich -0.180702 0.194188 -0.931 0.352
L1.Salzburg 0.177892 0.103043 1.726 0.084
L1.Steiermark 0.241467 0.140754 1.716 0.086
L1.Tirol 0.145838 0.093365 1.562 0.118
L1.Vorarlberg 0.189971 0.089049 2.133 0.033
L1.Wien -0.599502 0.189285 -3.167 0.002
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.301008 0.065463 4.598 0.000
L1.Burgenland 0.110494 0.034039 3.246 0.001
L1.Kärnten -0.023707 0.027657 -0.857 0.391
L1.Niederösterreich 0.055127 0.078823 0.699 0.484
L1.Oberösterreich 0.276025 0.067466 4.091 0.000
L1.Salzburg 0.002710 0.035800 0.076 0.940
L1.Steiermark -0.016451 0.048902 -0.336 0.737
L1.Tirol 0.095296 0.032438 2.938 0.003
L1.Vorarlberg 0.127155 0.030938 4.110 0.000
L1.Wien 0.078395 0.065763 1.192 0.233
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.210856 0.077076 2.736 0.006
L1.Burgenland -0.005770 0.040078 -0.144 0.886
L1.Kärnten 0.024950 0.032563 0.766 0.444
L1.Niederösterreich 0.029589 0.092805 0.319 0.750
L1.Oberösterreich 0.383788 0.079434 4.832 0.000
L1.Salzburg 0.093805 0.042151 2.225 0.026
L1.Steiermark 0.186164 0.057577 3.233 0.001
L1.Tirol 0.044264 0.038192 1.159 0.246
L1.Vorarlberg 0.100634 0.036427 2.763 0.006
L1.Wien -0.070528 0.077429 -0.911 0.362
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.567244 0.153177 3.703 0.000
L1.Burgenland 0.076635 0.079649 0.962 0.336
L1.Kärnten 0.005227 0.064715 0.081 0.936
L1.Niederösterreich -0.016763 0.184438 -0.091 0.928
L1.Oberösterreich 0.129800 0.157865 0.822 0.411
L1.Salzburg 0.047164 0.083769 0.563 0.573
L1.Steiermark 0.110874 0.114426 0.969 0.333
L1.Tirol 0.225708 0.075901 2.974 0.003
L1.Vorarlberg 0.018564 0.072393 0.256 0.798
L1.Wien -0.149539 0.153879 -0.972 0.331
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.171275 0.108396 1.580 0.114
L1.Burgenland -0.021713 0.056364 -0.385 0.700
L1.Kärnten -0.012588 0.045796 -0.275 0.783
L1.Niederösterreich 0.171067 0.130518 1.311 0.190
L1.Oberösterreich 0.373223 0.111713 3.341 0.001
L1.Salzburg -0.031793 0.059279 -0.536 0.592
L1.Steiermark -0.045121 0.080974 -0.557 0.577
L1.Tirol 0.195108 0.053711 3.633 0.000
L1.Vorarlberg 0.049395 0.051229 0.964 0.335
L1.Wien 0.159079 0.108893 1.461 0.144
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.221552 0.136770 1.620 0.105
L1.Burgenland 0.069450 0.071117 0.977 0.329
L1.Kärnten -0.048348 0.057783 -0.837 0.403
L1.Niederösterreich -0.035730 0.164682 -0.217 0.828
L1.Oberösterreich -0.094137 0.140955 -0.668 0.504
L1.Salzburg 0.028693 0.074796 0.384 0.701
L1.Steiermark 0.373289 0.102169 3.654 0.000
L1.Tirol 0.511497 0.067771 7.547 0.000
L1.Vorarlberg 0.192588 0.064638 2.979 0.003
L1.Wien -0.217064 0.137396 -1.580 0.114
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.099380 0.160338 0.620 0.535
L1.Burgenland 0.015518 0.083373 0.186 0.852
L1.Kärnten -0.104482 0.067741 -1.542 0.123
L1.Niederösterreich 0.232781 0.193061 1.206 0.228
L1.Oberösterreich 0.024254 0.165246 0.147 0.883
L1.Salzburg 0.221983 0.087685 2.532 0.011
L1.Steiermark 0.138650 0.119776 1.158 0.247
L1.Tirol 0.096083 0.079449 1.209 0.227
L1.Vorarlberg 0.020049 0.075777 0.265 0.791
L1.Wien 0.263734 0.161073 1.637 0.102
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.595000 0.087033 6.836 0.000
L1.Burgenland -0.021513 0.045255 -0.475 0.635
L1.Kärnten -0.001463 0.036770 -0.040 0.968
L1.Niederösterreich -0.016406 0.104795 -0.157 0.876
L1.Oberösterreich 0.274569 0.089697 3.061 0.002
L1.Salzburg 0.009262 0.047596 0.195 0.846
L1.Steiermark 0.002437 0.065015 0.037 0.970
L1.Tirol 0.079124 0.043126 1.835 0.067
L1.Vorarlberg 0.167977 0.041133 4.084 0.000
L1.Wien -0.083582 0.087432 -0.956 0.339
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.149824 -0.006247 0.213328 0.254479 0.065728 0.085133 -0.068100 0.154862
Kärnten 0.149824 1.000000 0.004770 0.193227 0.156457 -0.128899 0.162385 0.029043 0.303685
Niederösterreich -0.006247 0.004770 1.000000 0.290441 0.085540 0.219551 0.103399 0.057642 0.353109
Oberösterreich 0.213328 0.193227 0.290441 1.000000 0.293381 0.313508 0.086082 0.079082 0.122981
Salzburg 0.254479 0.156457 0.085540 0.293381 1.000000 0.156851 0.069036 0.078168 -0.024181
Steiermark 0.065728 -0.128899 0.219551 0.313508 0.156851 1.000000 0.099089 0.090516 -0.120713
Tirol 0.085133 0.162385 0.103399 0.086082 0.069036 0.099089 1.000000 0.147324 0.132632
Vorarlberg -0.068100 0.029043 0.057642 0.079082 0.078168 0.090516 0.147324 1.000000 0.095209
Wien 0.154862 0.303685 0.353109 0.122981 -0.024181 -0.120713 0.132632 0.095209 1.000000